package region

import (
	"context"
	"errors"
	"github.com/SpectatorNan/gorm-zero/gormc"
	"github.com/zeromicro/go-zero/core/stores/cache"
	"gorm.io/gorm"
)

var _ TRegionOpenCityModel = (*customTRegionOpenCityModel)(nil)

type (
	// TRegionOpenCityModel is an interface to be customized, add more methods here,
	// and implement the added methods in customTRegionOpenCityModel.
	TRegionOpenCityModel interface {
		tRegionOpenCityModel
		customTRegionOpenCityLogicModel
		FindAll(ctx context.Context) ([]*TRegionOpenCity, error)
	}

	customTRegionOpenCityModel struct {
		*defaultTRegionOpenCityModel
	}

	customTRegionOpenCityLogicModel interface {
	}
)

func (m customTRegionOpenCityModel) FindAll(ctx context.Context) ([]*TRegionOpenCity, error) {
	var resp []*TRegionOpenCity
	err := m.QueryNoCacheCtx(ctx, &resp, func(conn *gorm.DB, v interface{}) error {
		return conn.Model(&TRegionOpenCity{}).Find(&resp).Error
	})
	switch {
	case err == nil:
		return resp, nil
	case errors.Is(err, gormc.ErrNotFound):
		return nil, ErrNotFound
	default:
		return nil, err
	}
}

// NewTRegionOpenCityModel returns a model for the database table.
func NewTRegionOpenCityModel(conn *gorm.DB, c cache.CacheConf) TRegionOpenCityModel {
	return &customTRegionOpenCityModel{
		defaultTRegionOpenCityModel: newTRegionOpenCityModel(conn, c),
	}
}

func (m *defaultTRegionOpenCityModel) customCacheKeys(data *TRegionOpenCity) []string {
	if data == nil {
		return []string{}
	}
	return []string{}
}
